package com.rmt.www.serviceImpl;

import java.util.List;

import com.rmt.www.constant.ArtifactType;
import com.rmt.www.dao.DesignArtifactDao;
import com.rmt.www.dao.DesignArtifactRequestDao;
import com.rmt.www.dao.FeatureArtifactDao;
import com.rmt.www.dao.FeatureArtifactRequestDao;
import com.rmt.www.dao.ImplementationArtifactDao;
import com.rmt.www.dao.ImplementationArtifactRequestDao;
import com.rmt.www.dao.RequirementArtifactDao;
import com.rmt.www.dao.RequirementArtifactRequestDao;
import com.rmt.www.dao.TestArtifactDao;
import com.rmt.www.dao.TestArtifactRequestDao;
import com.rmt.www.dao.UserDao;
import com.rmt.www.service.ArtifactDetailQueryService;
import com.rmt.www.vo.DesignArtifact;
import com.rmt.www.vo.FeatureArtifact;
import com.rmt.www.vo.ImplementationArtifact;
import com.rmt.www.vo.RequirementArtifact;
import com.rmt.www.vo.TestArtifact;

public class ArtifactDetailQueryServiceImpl implements
		ArtifactDetailQueryService {

	private FeatureArtifactDao featureArtifactDao;
	
	private RequirementArtifactDao requirementArtifactDao;
	private DesignArtifactDao designArtifactDao;
	private ImplementationArtifactDao implementationArtifactDao;
	private TestArtifactDao testArtifactDao;
 	public FeatureArtifactDao getFeatureArtifactDao() {
		return featureArtifactDao;
	}

	public void setFeatureArtifactDao(FeatureArtifactDao featureArtifactDao) {
		this.featureArtifactDao = featureArtifactDao;
	}

	public RequirementArtifactDao getRequirementArtifactDao() {
		return requirementArtifactDao;
	}

	public void setRequirementArtifactDao(
			RequirementArtifactDao requirementArtifactDao) {
		this.requirementArtifactDao = requirementArtifactDao;
	}

	public DesignArtifactDao getDesignArtifactDao() {
		return designArtifactDao;
	}

	public void setDesignArtifactDao(DesignArtifactDao designArtifactDao) {
		this.designArtifactDao = designArtifactDao;
	}

	public ImplementationArtifactDao getImplementationArtifactDao() {
		return implementationArtifactDao;
	}

	public void setImplementationArtifactDao(
			ImplementationArtifactDao implementationArtifactDao) {
		this.implementationArtifactDao = implementationArtifactDao;
	}

	public TestArtifactDao getTestArtifactDao() {
		return testArtifactDao;
	}

	public void setTestArtifactDao(TestArtifactDao testArtifactDao) {
		this.testArtifactDao = testArtifactDao;
	}

	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	public UserDao userDao;
 	
	public List<RequirementArtifact> getRequirementList(int pid) {
		List<RequirementArtifact> list = requirementArtifactDao.getRequirementArtifactByPId(pid);
		int authorid, updaterid;
		for (int i = 0; i < list.size(); i++) {
			authorid = list.get(i).getAuthorId();
			updaterid = list.get(i).getUpdateUserId();
			list.get(i).set_authorname(userDao.getUser(authorid).getName());
			if (updaterid != 0)
			list.get(i).set_updatername(userDao.getUser(updaterid).getName());
			list.get(i).setArtifacttype(ArtifactType.REQUIREMENT);
		}
		return list;
	}

	public List<DesignArtifact> getDesignList(int pid) {
		List<DesignArtifact> list = designArtifactDao.getDesignArtifactsByPId(pid);
		int authorid, updaterid;
		for (int i = 0; i < list.size(); i++) {
			authorid = list.get(i).getCreaterid();
			updaterid = list.get(i).getUpdaterid();
			list.get(i).set_authorname(userDao.getUser(authorid).getName());
			if (updaterid != 0)
			list.get(i).set_updatername(userDao.getUser(updaterid).getName());
			list.get(i).setArtifacttype(ArtifactType.DESIGN);
		}
		return list;
	}
	public List<FeatureArtifact> getFeatureList(int pid) {
		List<FeatureArtifact> list = featureArtifactDao.getFeatureArtifactsByPId(pid);
		
		int authorid, updaterid;
		for (int i = 0; i < list.size(); i++) {
			authorid = list.get(i).getAuthorId();
			updaterid = list.get(i).getUpdateUserId();
			list.get(i).set_authorname(userDao.getUser(authorid).getName());
			if (updaterid != 0)
				list.get(i).set_updatername(userDao.getUser(updaterid).getName());
			list.get(i).setArtifacttype(ArtifactType.FEATURE);
		}
		return list;
	}
	public List<ImplementationArtifact> getImplementationList(int pid) {
		List<ImplementationArtifact> list = implementationArtifactDao.getImplementationArtifactsByPId(pid);
		int authorid, updaterid;
		for (int i = 0; i < list.size(); i++) {
			authorid = list.get(i).getCreaterid();
			updaterid = list.get(i).getUpdaterid();
			list.get(i).set_authorname(userDao.getUser(authorid).getName());
			if (updaterid != 0)
			list.get(i).set_updatername(userDao.getUser(updaterid).getName());
			list.get(i).setArtifacttype(ArtifactType.IMPLEMENTATION);
		}
		return list;
	}

	public List<TestArtifact> getTestCaseList(int pid) {
		List<TestArtifact> list = testArtifactDao.getTestArtifactsByPId(pid);
		int authorid, updaterid;
		for (int i = 0; i < list.size(); i++) {
			authorid = list.get(i).getCreaterid();
			updaterid = list.get(i).getUpdaterid();
			list.get(i).set_authorname(userDao.getUser(authorid).getName());
			if (updaterid != 0)
			list.get(i).set_updatername(userDao.getUser(updaterid).getName());
			list.get(i).setArtifacttype(ArtifactType.TESTCASE);
		}
		return list;
	}

}
